package cn.yunhe.servlet;

import cn.yunhe.dao.IUserAccount;
import cn.yunhe.entity.userentity.UserAccount;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 王羊
 * 异步
 * 用户名
 */
@WebServlet("/SearchUserByAccountServlet")
public class SearchUserByAccountServlet extends HttpServlet {
    SqlSession session = null;
    IUserAccount iUserAccount=null;
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try{
            session = SqlSessionFactoryUtil.getSqlSession();
            iUserAccount=session.getMapper(IUserAccount.class);
            PrintWriter out = response.getWriter();
            String account = request.getParameter("account");
            if (account!=null&&!"".equals(account)){
                UserAccount userAccount = iUserAccount.denglu2(account);
                response.setContentType("text/html;charset=UTF-8");

                if (userAccount==null){
                    out.print("false");
                }
                else {
                    out.print("true");
                }
        }

        }finally {
            session.close();
        }





    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

}
